package 结业考试;

import java.util.ArrayList;
import java.util.Collection;

public class StudentArrayLIst {
    public static void main(String[] args) {
        //子接口
//        ArrayList<Student> students = new ArrayList<>();
        //主接口
        Collection <Student> students = new ArrayList();

//        Student r1 = new Student("王梅");

        students.add(new Student("张三"));
        students.add(new Student("李四"));
        students.add(new Student("王五"));


        // 用增强for循环 遍历学生信息
        System.out.println("原始学生列表：");
        for (Student student : students) {
            System.out.println(student);
        }

        // 修改
        for (Student student : students) {
            if (student.getName().equals("张三")) {
                student.setName("张三丰");
            }
        }

        // 打印修改后的学生列表
        System.out.println("修改后的学生列表：");
        for (Student student : students) {
            System.out.println(student);
        }

        //判断当前集合集合是否包含“王五”
//        students.contains("王五");
//        System.out.println(students.contains("王五"));

        // 删除王五
        students.removeIf(student -> student.getName().equals("王五"));//如果在集合中找到“王五”，便删除
//        students.clear();清空

        // 打印删除后的学生列表
        System.out.println("删除王五后的学生列表：");
        for (Student student : students) {
            System.out.println(student);
        }

    }

}
//集合